# !/usr/bin/env python
# -*- coding:utf-8 -*-
'''版本信息

历史:
    2018-10-24 姚彧 创建
    2018-10-25 使用新的EventDispatcher
    2018-10-26 为了解决重复引用,将get_app_path放到来模块
    2018-11-10 ... 发布1.0 belta版
'''

from events.EventCenter import (EventContext, EventDispatcher)

class AppEnviron(object):
    PATH_NAME = 'App.Environ.Get'
    PATH_NAME2 = 'App.Environ.GetAll'
    PROP_NAME = 'key'

    app_name = "Delaunay构网"
    author = "姚彧"
    email = "yao_yu@126.com"

    version = '0.1(belta)'
    version_date = '2018.11.30'
    full_version = '%s - %s' % (version_date, version)
    release = True

    @staticmethod
    def get_app_path():
        import os
        return os.path.dirname(__file__)

    @classmethod
    def on_event_app_environ_get(cls, context: EventContext):
        assert context.path == cls.PATH_NAME
        prop_name = context.get(cls.PROP_NAME)
        if isinstance(prop_name, str) and hasattr(cls, prop_name):
            context['value'] = getattr(cls, prop_name)
            return True

    @classmethod
    def on_event_app_environ_getall(cls, context: EventContext):
        assert context.path == cls.PATH_NAME2
        context['value'] = {i: getattr(cls, i) for i in dir(cls) if not i.startswith('_')}
        return True

EventDispatcher().register(AppEnviron.PATH_NAME, AppEnviron.on_event_app_environ_get)
EventDispatcher().register(AppEnviron.PATH_NAME2, AppEnviron.on_event_app_environ_getall)